@extends('admin.home.main')

@section('body')
<section id="main-content">
	  <section class="wrapper">
		<h3>标签添加</h3>
		<!-- BASIC FORM ELELEMNTS -->
		<div class="row mt">
		  <div class="col-lg-12">
			<div class="form-panel">
			  <form class="form-horizontal style-form" action="/admin/tag/insert" method="post">
			  	<input type="hidden" id="_token" name="_token" value="{{csrf_token()}}">

			  	<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">标签父级名称</label>
				  <div class="col-sm-10">
					<select class="form-control" id="tid" name="tid" style="width:200px">
	               		<option value="0">请选择</option>
	               		<option value="1">心智</option>
	               		<option value="2">认知</option>
	               		<option value="3">体魄</option>
	                </select>
				  </div>
				</div>

				<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">标签名称</label>
				  <div class="col-sm-10">
					<input type="text" style="width:400px;" class="form-control" id="name" name="name" placeholder="请输入标签名称" size="50">
				  </div>
				</div>
				
				<button type="button" id="save" class="btn btn-success">提交</button>
				<button type="reset" class="btn btn-primary">重置</button>
			  </form>
			</div>
		  </div>
		  <!-- col-lg-12-->
		</div>

		
	  </section>
	  <!-- /wrapper -->
	</section>
<script type="text/javascript">
	$('#save').click(function(){
		var _token = $('#_token').val(),
			_tid = $('#tid').val(),
			_tag_name = $('#name').val();
			
		if(!_tag_name){
			alert('请输入栏目名称');
			return false;
		} 

		$.ajax({
			url:'/admin/tag/insert',
			type:'post',
			data:{'_token':_token,'tid':_tid,'name':_tag_name},
			dataType:'json',
			success:function(msg){
				if(msg.code == 200){
					alert('添加成功');
					location.href="/admin/tag/list";
				}else if(msg.code == 300){
					alert('标签已存在,请勿重复添加');
					location.reload();
				}else{
					alert('添加失败');
					location.reload();
				}
			}
		})
	})
</script>
@endsection